package com.mt.course.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.course.entity.ExaminationItemWrongEntity;
import com.mt.course.mapper.ExaminationItemWrongEntityMapper;

@Component
public class ExaminationItemWrongServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ExaminationItemWrongServiceModel.class);

    @Autowired
    private ExaminationItemWrongEntityMapper examinationItemWrongEntityMapper;

    public ServiceResult<List<ExaminationItemWrongEntity>> selectList(Map<String, Object> params,
        PagerInfo<?> pagerInfo) {
        Assert.notNull(this.examinationItemWrongEntityMapper,
            "Property 'examinationItemWrongEntityMapper' is required.");
        ServiceResult<List<ExaminationItemWrongEntity>> result = new ServiceResult<List<ExaminationItemWrongEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }

            result.setResult(this.examinationItemWrongEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationItemWrongServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<ExaminationItemWrongEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.examinationItemWrongEntityMapper,
            "Property 'examinationItemWrongEntityMapper' is required.");
        ServiceResult<ExaminationItemWrongEntity> result = new ServiceResult<ExaminationItemWrongEntity>();
        try {
            result.setResult(this.examinationItemWrongEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationItemWrongServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> selectCount(Map<String, Object> params) {
        Assert.notNull(this.examinationItemWrongEntityMapper,
            "Property 'examinationItemWrongEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int count = 0;
        try {
            count = this.examinationItemWrongEntityMapper.selectCount(params);
            result.setResult(count);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationItemWrongServiceModel][selectCount]：query selectCount occur exception", e);
            throw new RuntimeException(e.getMessage());
        }
        return result;
    }

    public ServiceResult<Integer> insert(ExaminationItemWrongEntity examinationItemWrongEntity) {
        Assert.notNull(this.examinationItemWrongEntityMapper,
            "Property 'examinationItemWrongEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.examinationItemWrongEntityMapper.insert(examinationItemWrongEntity);
            if (save > 0) {
                id = examinationItemWrongEntity.getExaminationItemWrongId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationItemWrongServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insertList(List<ExaminationItemWrongEntity> examinationItemWrongList) {
        Assert.notNull(this.examinationItemWrongEntityMapper,
            "Property 'examinationItemWrongEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.examinationItemWrongEntityMapper.insertList(examinationItemWrongList);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationItemWrongServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(ExaminationItemWrongEntity examinationItemWrongEntity) {
        Assert.notNull(this.examinationItemWrongEntityMapper,
            "Property 'examinationItemWrongEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.examinationItemWrongEntityMapper.updateByPrimaryKeySelective(examinationItemWrongEntity);
            if (save > 0) {
                id = examinationItemWrongEntity.getExaminationItemWrongId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationItemWrongServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(ExaminationItemWrongEntity examinationItemWrongEntity) {
        Assert.notNull(this.examinationItemWrongEntityMapper,
            "Property 'examinationItemWrongEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.examinationItemWrongEntityMapper.updateByPrimaryKeySelective(examinationItemWrongEntity);
            if (save > 0) {
                id = examinationItemWrongEntity.getExaminationItemWrongId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationItemWrongServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer examinationItemWrongId) {
        Assert.notNull(this.examinationItemWrongEntityMapper,
            "Property 'examinationItemWrongEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            int save = this.examinationItemWrongEntityMapper.deleteByPrimaryKey(examinationItemWrongId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationItemWrongServiceModel][updateByPrimaryKeySelective]:query update occur exception",
                e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByCustomerExamination(Map<String, Object> params) {
        Assert.notNull(this.examinationItemWrongEntityMapper,
            "Property 'examinationItemWrongEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            int save = this.examinationItemWrongEntityMapper.deleteByCustomerExamination(params);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationItemWrongServiceModel][deleteByCustomerExamination]:query update occur exception",
                e);
        }
        return result;
    }
}
